﻿@model RedirectManagementViewModel
@using Orchard.ContentManagement;
@using Redirect404.Models;
@using Redirect404.ViewModels;

@{ Layout.Title = T("Redirects").ToString(); }

@using (Html.BeginFormAntiForgeryPost()) {
<table class="items">
    <colgroup>
        <col id="RequestUrl" />
        <col id="DestinationUrl" />
        <col id="Order" />
        <col id="Regex" />
        <col id="Type" />
        <col id="Actions" />
    </colgroup>
    <thead>
        <tr>
            <td scope="col">@T("Request Url")</td>
            <td scope="col">@T("Destination Url")</td>
            <td scope="col">@T("Order")</td>
            <td scope="col">@T("Regex")</td>
            <td scope="col">@T("Type")</td>
            <td scope="col"></td>
        </tr>
    </thead>
    <tbody>@{ 
        var redirectPartEntryIndex = 0;
        foreach (var redirectPartEntry in Model.RedirectItemEntries) {
            var i = redirectPartEntryIndex;
            <tr>
                <td><input type="text" class="text-box" name="@Html.NameOf(m => m.RedirectItemEntries[i].RequestedURL)" value="@redirectPartEntry.RequestedURL" /></td>
                <td><input type="text" class="text-box" name="@Html.NameOf(m => m.RedirectItemEntries[i].DestURL)" value="@redirectPartEntry.DestURL" /></td>
                <td><input type="text" class="text-box" name="@Html.NameOf(m => m.RedirectItemEntries[i].ProcessOrder)" value="@redirectPartEntry.ProcessOrder" /></td>
                <td>@Html.EditorFor(m => m.RedirectItemEntries[i].UseRegex)</td>
                <td><input type="text" class="text-box" name="@Html.NameOf(m => m.RedirectItemEntries[i].RedirectType)" value="@redirectPartEntry.RedirectType" /></td>
                <td><input type="hidden" name="@Html.NameOf(m => m.RedirectItemEntries[i].RedirectEntryId)" value="@redirectPartEntry.RedirectEntryId" /><a href="@Html.AntiForgeryTokenGetUrl(Url.Action("Delete", new {id = redirectPartEntry.RedirectEntryId}))" class="remove">@T("Delete")</a></td>
            </tr>
            ++redirectPartEntryIndex;
        }
    }
    </tbody>
</table>
<fieldset class="actions"><button type="submit" class="button">@T("Update All")</button></fieldset>
}

<h2>@T("Add New Item")</h2>
@using (Html.BeginFormAntiForgeryPost(Url.Action("create"), FormMethod.Post)) {
<table class="menu items">
    <colgroup>
        <col id="AddRequestUrl" />
        <col id="AddDestinationUrl" />
        <col id="AddOrder" />
        <col id="AddRegex" />
        <col id="AddType" />
        <col id="AddActions" />
    </colgroup>
    <tbody>

        <tr>
            <td>
                <label for="RequestedURL">@T("Requested URL")</label>
                @Html.EditorFor(m => m.NewEntry.RequestedURL)
            </td>
            <td>
                <label for="DestURL">@T("Destination URL")</label>
                @Html.EditorFor(m => m.NewEntry.DestURL)
            </td>
            <td>
                <label for="Order">@T("Order")</label>
                @Html.EditorFor(m => m.NewEntry.ProcessOrder)
            </td>
            <td>
                <label for="UseRegex">@T("Regex")</label>
                @Html.EditorFor(m => m.NewEntry.UseRegex)
            </td>
            <td>
                <label for="RedirectType">@T("Type")</label>
                @Html.TextBox("NewEntry.RedirectType", "301")
            </td>
            <td><button class="add" type="submit">@T("Add")</button></td>
        </tr>
        <tr>
            <td colspan="6">
            <h2>Regular Expressions (Regex)</h2>
            To use regular expressions place the regex pattern in the Requested URL field and check the Regex checkbox, you can use groups in the destination url as follows:<br />
            <br />
            <i>/Redirect/Path/{1}</i>
            </td>
        </tr>
    </tbody>
</table>
}